<template>
    <div class="news_info">
        <!-- 大标题 -->
        <h3 class="news_title">{{ infoList.title }}</h3>
        <!-- 子标题 -->
            <p class="news_sub">
                <span>
                   发表时间： {{ infoList.add_time | dateFormat() }}
                </span>
                <span>
                    点击：{{ infoList.click }}次
                </span>
            </p>

            <hr>
            <!-- 内容区 -->
           <div class="new_content" v-html="infoList.content">
               
            </div> 
            <!-- 评论子组件 -->
               <comment-box :newsId=this.newsId></comment-box>    
    </div>
</template>

<script>
import { Toast } from "mint-ui";
// 导入子组件
import comment from '../subComponents/comment.vue'
export default {
    data() {
        return {
            newsId:this.$route.params.id,
            infoList:{}
        }
    },
    created() {
         this.getNewsInfo()
    },
    methods: {
        getNewsInfo(){
            this.$http.get('api/getnew/'+this.newsId).then((result) => {
                if (result.body.status == 0) {
                    this.infoList = result.body.message[0]
                    this.infoList.content = this.infoList.content.replace(
            /http:\/\/ofv795nmp\.bkt\.clouddn\.com\/\/upload\/201504\/16\/\d+\.jpg/g,
            "http://img3.bitautoimg.com/autoalbum/files/20150414/393/18124039376154_3983278_630x765__m1.jpg"
          );
                }
            }).catch((err) => {
                Toast("文章加载失败！");
            });
        }
    },
    components:{ // 用来注册子组件的节点
        'comment-box':comment
    }
}
</script>

<style lang="less" >
    .news_info{
        padding: 0 4px;
        .news_title{
            font-size: 16px;
            text-align: center;
            margin: 15px 0;
            color: red;
        }
        .news_sub{
            font-size: 13px;
            color: #226aff;
            display: flex;
            justify-content: space-between;
        }
        .new_content{
            img{
                width: 100%;
            }
        }
    }
</style>

